package boot.spring.service.impl;

import boot.spring.mapper.ActorMapper;
import boot.spring.mapper.PostMapper;
import boot.spring.po.Actor;
import boot.spring.po.Post;
import boot.spring.service.ActorService;
import boot.spring.service.PostService;
import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.DEFAULT,timeout=5)
@Service("postservice")
public class PostServiceImpl implements PostService {
	@Autowired
	public PostMapper postMapper;


	@Override
	public List<Post> gelallpost() {
		return postMapper.gelallpost();
	}

	@Override
	public void savePost(Post post) {
		postMapper.insertPost(post);
	}

	@Override
	public void deletePost(int postId) {
		postMapper.deletePost(postId);
	}

	@Override
	public Page<Post> getPostsByPage(Pageable pageable) {
		List<Post> posts = postMapper.getPostsByPage(pageable.getOffset(), pageable.getPageSize());
		long total = postMapper.getTotalCount();
		return new PageImpl<>(posts, pageable, total);
	}

	@Override
	public Post getPostById(int postId) {

		return postMapper.getPostById(postId);
	}
}
